package com.yunfangdata.web.controller;


import com.yunfangdata.domain.DataDict;
import com.yunfangdata.query.QueryObject;
import com.yunfangdata.service.IDataDictService;
import com.yunfangdata.util.JsonResult;
import com.yunfangdata.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("dataDict")
public class DataDictController {

    @Autowired
    private IDataDictService dataDictService;

    @RequestMapping("")
    public String index(){
        return "dataDict/list";
    }


    @RequestMapping("list")
    @ResponseBody
    public PageResult list(QueryObject qo){
        return dataDictService.query(qo);
    }


    @RequestMapping("save")
    @ResponseBody
    public JsonResult save(DataDict dataDict){
        JsonResult result = new JsonResult();
        try {
            dataDictService.save(dataDict);
        } catch (Exception e) {
            e.printStackTrace();
            result = new JsonResult("保存失败");
        }
        return result;
    }


    @RequestMapping("update")
    @ResponseBody
    public JsonResult update(DataDict dataDict){
        JsonResult result = new JsonResult();
        try {
            dataDictService.update(dataDict);
        } catch (Exception e) {
            e.printStackTrace();
            result = new JsonResult("编辑失败");
        }
        return result;
    }

    @RequestMapping("delete")
    @ResponseBody
    public JsonResult delete(Long id){
        JsonResult result = new JsonResult();
        try {
            dataDictService.delete(id);
        } catch (Exception e) {
            e.printStackTrace();
            result = new JsonResult("删除失败");
        }
        return result;
    }

    @RequestMapping("queryByParentIdIsNull")
    @ResponseBody
    public List<DataDict> queryByParentIdIsNull(){
        return dataDictService.queryByParentIdIsNull();
    }

    @RequestMapping("queryByParentIdChildren")
    @ResponseBody
    public List<DataDict> queryByParentIdChildren(Long parentId){
        List<DataDict> dataDicts = dataDictService.queryByParentIdChildren(parentId);
        return dataDicts;
    }

    @RequestMapping("datas")
    @ResponseBody
    public List<DataDict> datas(Long perentId){
        return dataDictService.selectDataDictByperentId(perentId);
    }




    //查询校区
    @RequestMapping("selsectForSchool")
    @ResponseBody
    public List<DataDict> selsectForSchool(Long parentId){
        return dataDictService.queryByParentId(parentId);
    }


    //查询学科
    @RequestMapping("selsectForDiscipline")
    @ResponseBody
    public List<DataDict> selsectForDiscipline(Long parentId) {
        return dataDictService.queryByParentId(parentId);
    }


    //招聘相关所有信息
    @RequestMapping("selectDataDictByparentId")
    @ResponseBody
    public List<DataDict> selectDataDictByparentId(Long parentId) {

        return dataDictService.queryByParentId(parentId);
    }



}
